package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.NewsFileAddDTO;
import org.jsola.hr.dto.NewsFileUpdateDTO;
import org.jsola.hr.entity.NewsFileDO;
import org.jsola.hr.query.NewsFileQuery;
import org.jsola.hr.service.INewsFileService;
import org.jsola.hr.vo.NewsFileVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 官网新闻内容附带的附件
 *
 * @author zhr
 */
@Component
public class NewsFileTestHelper extends BaseTestHelper {
    
    @Autowired
    private INewsFileService newsFileService;

    /**
     * 生成add测试数据
     * @return NewsFileAddDTO
     */
    public NewsFileAddDTO getNewsFileAddDTO(){
        NewsFileAddDTO newsFileAddDTO = new NewsFileAddDTO();
        newsFileAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        newsFileAddDTO.setNewsInfoId(getRandomValue("varchar",32));
        newsFileAddDTO.setUrl(getRandomValue("varchar",200));
        newsFileAddDTO.setName(getRandomValue("varchar",50));
        return newsFileAddDTO;
    }


    /**
     * 生成update测试数据
     * @return NewsFileUpdateDTO
     */
    public NewsFileUpdateDTO getNewsFileUpdateDTO(NewsFileVO newsFileVO){
        return newsFileService.selectDOById(newsFileVO.getId(), SITE_ID).to(NewsFileUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return NewsFileQuery
     */
    public NewsFileQuery getNewsFileQuery() {
        NewsFileQuery newsFileQuery = new NewsFileQuery();
        List<NewsFileDO> newsFileDOList = newsFileService.list(new NewsFileDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(newsFileDOList)) {
            NewsFileDO newsFileDO = newsFileDOList.get(0);
            newsFileQuery = newsFileDO.to(NewsFileQuery.class);
        }
        return newsFileQuery;
    }

    /**
     * 保存示例
     * @return NewsFileVO
     */
    public NewsFileVO saveNewsFileExample(){
        NewsFileAddDTO addDTO = this.getNewsFileAddDTO();
        NewsFileVO newsFileVO = newsFileService.save(addDTO,buildTokenUser());
        return newsFileVO;
    }


}

